<template>
  <up-swiper
      v-if="list1.length>0"
      :list="list1"
      height="340rpx"
      @click="selectList1"
  ></up-swiper>
  <up-gap v-if="list2.length>0" height="12rpx"></up-gap>
  <up-swiper
      v-if="list2.length>0"
      :list="list2"
      height="340rpx"
      @click="selectList2"
  ></up-swiper>
</template>
<script setup>

const props = defineProps({
  params: {
    type: Object,
    default: {}
  }
})

const swiperList1 = ref([])
const swiperList2 = ref([])

const list1 = computed(() => {
  return swiperList1.value.map(item => item.cover)
})
const list2 = computed(() => {
  return swiperList2.value.map(item => item.img)
})

// 获取后台轮播图
const getSwiper1 = async () => {
  const res = await qly.api.user.hqgglb()
  if (res.code === 1) {
    swiperList1.value = res.data
  } else {
    qly.dialog.apiError(res).catch()
  }
}
// 获取代理商轮播图
const getSwiper2 = async () => {
  const res = await qly.api.user.dlsgg({
    province: props.params.province,
    city: props.params.city,
    district: props.params.district,
  })
  if (res.code === 1) {
    swiperList2.value = res.data
    console.log('list2',list2.value)
  }
}

const selectList1 = (index) => {
  const id = swiperList1.value[index].id
  qly.page.open('/pages/my/swiperInfo/index', {id})
}

const selectList2 = (index) => {
  const id = swiperList2.value[index].id
  qly.page.open('/pages/my/agentSwiperInfo/index', {id})
}

const refresh = () => {
  getSwiper1()
  getSwiper2()
}

onMounted(() => {
  refresh()
})

defineExpose({
  refresh
})
</script>
<style scoped lang="scss">

</style>